<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: rgb(90, 57, 121);
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son">

        </div>
    </div>

    <script>
        // 捕获  document --> html --> body -->div
        // 冒泡  div --> body --> html --> document


        let father = document.querySelector('.father')
        let son = document.querySelector('.son')

        // 捕获阶段 true 
        // 冒泡 默认false
        father.addEventListener('click', function() {
            alert("父亲")
        })
        son.addEventListener('click', function(e) {
            alert("儿子")
            // 阻止冒泡到父亲
            e.stopPropagation()
            //  阻止默认行为
            // e.preventDefault()
        })

        // 阻止传播(包括捕获和冒泡)
        // obj.stopPropagation()

        // 移除事件监听
        // 匿名函数无法移除
        let dom = function() {
            alert("DOM")
        }
        document.removeEventListener('click', dom)



    </script>
</body>
</html>